package com.chexiehui.jc.ui.activity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.ActivityOptionsCompat;
import android.view.WindowManager;

import com.chexiehui.jc.R;
import com.chexiehui.jc.utils.SerializableSpTools;

import cn.jpush.android.api.InstrumentedActivity;

public class WelcomeActivity extends InstrumentedActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 不显示系统的标题栏，保证windowBackground和界面activity_main的大小一样，显示在屏幕不会有错位（去掉这一行试试就知道效果了）
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mHandler.sendEmptyMessageDelayed(0, 2000);
        setContentView(R.layout.activity_welcome);
    }

    @SuppressLint("HandlerLeak")
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            gotoActivity();
        }
    };

    private void gotoActivity() {
        //检测账号是否登录
        Class clz = null;
        if (SerializableSpTools.isLogin()) {
            clz = MainActivity.class;
        } else {
            clz = LoginActivity.class;
        }
        startActivity(new Intent(this, clz),
                ActivityOptionsCompat.makeCustomAnimation(this, R.anim.anim_fade_in, R.anim.anim_fade_out).toBundle());
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
            overridePendingTransition(R.anim.anim_fade_in, R.anim.anim_fade_out);
        }
        finish();
    }
}
